package model

import (
	"strings"
)

var fieldType2ProtoTypeMap = map[string]string{
	"tinyint":   "int32",
	"smallint":  "int32",
	"mediumint": "int32",
	"int":       "int32",
	"integer":   "int32",
	"bigint":    "int64",
	// "float":     "float32",
	// "double":    "float64",
}

type Sql2ProtoReq struct {
	Data string `json:"data" valid:"required,gt=15"`
}

// GetProtoType 获取字段类型
func GetProtoType(filedType string) string {
	// 这里需要处理, 如果有可能为: int(11)
	endIndex := strings.Index(filedType, "(")
	if endIndex == -1 {
		endIndex = len(filedType) - 1
	}
	filedType = filedType[:endIndex]
	if v, ok := fieldType2ProtoTypeMap[filedType]; ok {
		return v
	}
	return "string"
}
